package com.zjs.practice.controller;

import com.zjs.practice.service.MysqlPracticeService;
import com.zjs.practice.service.RedisPracticeService;
import com.zjs.practice.service.ThreadPoolPracticeService;
import com.zjs.practice.domain.Message;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试控制器
 * @Author zhu
 * @Date 2019/12/31 21:37
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/test2")
@Api(value = "测试控制器")
public class TestController2 {

    @Resource
    private MysqlPracticeService mysqlPracticeService;

    @Resource
    private ThreadPoolPracticeService threadPoolPracticeService;

    @Resource
    private RedisPracticeService redisPracticeService;

    @RequestMapping(value ="/test", method= RequestMethod.POST)
    public Message test(HttpServletResponse response){
        log.info("测试入参");
        try {
            mysqlPracticeService.test();
            return Message.ok();
        } catch (Exception e) {
            log.error("操作异常", e);
            return Message.error();
        }
    }

    @CrossOrigin(origins = "http://127.0.0.1:8020")
    @RequestMapping(value ="/test2", method= RequestMethod.POST)
    public String test2(){
        return "测试内容";
    }

    /**
     * 线程池测试
     * @return
     */
    @RequestMapping(value ="/testThreadPoolExecutor", method= RequestMethod.POST)
    public Message testThreadPoolExecutor() {
        return threadPoolPracticeService.testThreadPoolExecutor();
    }

    /**
     * Redis测试
     * @return
     */
    @RequestMapping(value ="/testRedis", method= RequestMethod.POST)
    public Message testRedis() {
        return redisPracticeService.test();
    }
}
